package com.vvlive.caibao.smartcity.utils;

import android.os.Handler;
import android.os.Message;

import com.vvlive.caibao.smartcity.view.PullToRefreshLayout;

public class MyRefreshListener implements PullToRefreshLayout.OnRefreshListener {

    private static final long DELAY = 3000;
    private static final int REFRESH_FINISH = 0;
    private static final int LOAD_FINISH = 1;

    private Handler mHandler = new Handler(){
        @Override
        public void handleMessage(Message msg) {
            int what = msg.what;
            PullToRefreshLayout layout = (PullToRefreshLayout) msg.obj;
            if(what == REFRESH_FINISH){
                layout.refreshFinish(REFRESH_FINISH);
            }else if(what == LOAD_FINISH){
                layout.loadmoreFinish(LOAD_FINISH);
            }
        }
    };
    @Override
    public void onRefresh(final PullToRefreshLayout pullToRefreshLayout) {
        mHandler.sendMessageDelayed(mHandler.obtainMessage(REFRESH_FINISH, pullToRefreshLayout), DELAY);
    }

    @Override
    public void onLoadMore(final PullToRefreshLayout pullToRefreshLayout) {
        mHandler.sendMessageDelayed(mHandler.obtainMessage(LOAD_FINISH, pullToRefreshLayout), DELAY);
    }

}
